import weakref

stock = weakref.WeakValueDictionary()


class Cheese:
    def __init__(self, kind) -> None:
        self.kind = kind

    def __repr__(self):
        return 'Cheese(%r)' % self.kind


catalog = [Cheese('Red'), Cheese('Green'), Cheese('blue')]
for cheese in catalog:
    stock[cheese.kind] = cheese
print(sorted(stock.keys()))   # ['Green', 'Red', 'blue']
del catalog
print(sorted(stock.keys()))   # ['blue']
del cheese
print(sorted(stock.keys()))   # []
